#include <at89c51RC2.h>
#include <Timer0.h>
#include <Delay.h>

sbit BEEP=P2^5;

//三组 1 1# 2 2# 3 4 4# 5 5# 6 6# 7 一行12个
unsigned int FreqTable[]={
	63777,63872,63969,64054,64140,61216,64291,64360,64426,64489,64547,64607,
	64655,64704,64751,64795,64837,64876,64913,64948,64981,65012,65042,65070,
  65095,65120,65144,65166,65186,65206,65255,65242,65259,65274,65289,65303
}  ;

unsigned int Music[]={12,12,19,19,21,21,19,17,17,16,16,14,14,12};
unsigned char Music_Time[]={500,500,500,500,500,500,1000,500,500,500,500,500,500,1000};

unsigned int FreqSelect,MusicSelect,Music_TimeSelect;

void main()
{
	Timer0_Init();
	while(1)
	{
		if(Music[MusicSelect]!=0xFF && Music_Time[Music_TimeSelect]!=0xFF)
		{
		FreqSelect=Music[MusicSelect];
		MusicSelect++;
		Delay(Music_Time[Music_TimeSelect]);
		Music_TimeSelect++;
		TR0=0;
		Delay(5);
		TR0=1;
		}
		else
		{
			TR0=0;
			while(1);
		}
	}
}

void Timer0_Routine() interrupt 1  //溢出时中断
{
	TL0 = FreqTable[FreqSelect]%256;		 
	TH0 = FreqTable[FreqSelect]/256;
	BEEP=!BEEP;
}